package fi.tuomio.helloscala
import java.net._
import java.io._

object ClientApp {

	def main(args: Array[String]) {
		val ia = InetAddress.getByName("localhost")
		val socket = new Socket(ia, 12111)	  
		try {
			client(socket)
		} catch {case e:SocketException => {}}
		finally (socket.close())
	}  

	def client(socket:Socket) {
		val out = new OutputStreamWriter(socket.getOutputStream, "ISO-8859-1")
		val in = new BufferedReader(new InputStreamReader(socket.getInputStream, "ISO-8859-1"))
		var line = ""
		do {
			println("-> " + in.readLine())
			line = readLine()
			write(out, line)
		} while ( line != "quit")
	}

	def write(out: OutputStreamWriter, line:String) {
		out.write(line + "\n")
		out.flush
	}
}
